package sorting;

/**
 * Big O notation : O(n^2)
 * @author Gatsby Lee
 */
public class SelectionSort {

	/**
	 * Sort the given data array.
	 * @param data : data the array to be sorted.
	 */
	public static <T extends Comparable<? super T>> void sort(T[] data) {

		for (int minIndex = 0; minIndex < data.length - 1; minIndex++) {
			for (int currentIndex = minIndex + 1; currentIndex < data.length; currentIndex++) {
				if (data[minIndex].compareTo(data[currentIndex]) > 0) {
					T element = data[minIndex];
					data[minIndex] = data[currentIndex];
					data[currentIndex] = element;
				}
			}
		}
	}
}
